package com.example.video.helper

import android.view.View
import com.example.video.view.CoverVideoPlayerView
import com.shuyu.gsyvideoplayer.listener.GSYMediaPlayerListener

object VideoPlayerHelper {
    private  var mVideoPlayerView : CoverVideoPlayerView ? =null

    private  var mMediaPlayerListener : GSYMediaPlayerListener?=null

    fun optionPlayer(gsyVideoPlayer: CoverVideoPlayerView,url: String,cache:Boolean,title : String){
        //增加title
        gsyVideoPlayer.titleTextView.visibility = View.GONE
        //设置返回键
        gsyVideoPlayer.backButton.visibility = View.VISIBLE
        //设置全屏按键功能
        gsyVideoPlayer.fullscreenButton.setOnClickListener {
            gsyVideoPlayer.startWindowFullscreen(gsyVideoPlayer.context, false, true)
        }
        //是否根据视频尺寸，自动选择竖屏全屏或者横屏全屏
        gsyVideoPlayer.isAutoFullWithSize = true
        //音频焦点冲突时是否释放
        gsyVideoPlayer.isReleaseWhenLossAudio = true
        //全屏动画
        gsyVideoPlayer.isShowFullAnimation = false
        //小屏时不触摸滑动
        gsyVideoPlayer.setIsTouchWiget(false)

        gsyVideoPlayer.setVideoUrl(url)

        gsyVideoPlayer.setVideoCache(cache)

        gsyVideoPlayer.setVideoTitle(title)
    }


    fun savePlayState(videoPlayerView: CoverVideoPlayerView) {
        mVideoPlayerView = videoPlayerView.saveState()
        mMediaPlayerListener = videoPlayerView
    }

    fun clonePlayState(videoPlayerView: CoverVideoPlayerView) {
        mVideoPlayerView?.let { videoPlayerView.cloneState(it) }
    }

    fun release() {
        if (mMediaPlayerListener!= null) {
            mMediaPlayerListener?.onAutoCompletion()
        }
        mVideoPlayerView = null
        mMediaPlayerListener = null
    }

}